package com.fierce.cloud.ota.service.impl;

import com.fierce.cloud.core.common.service.BaseService;
import com.fierce.cloud.ota.dao.UserMapper;
import com.fierce.cloud.ota.model.User;
import com.fierce.cloud.ota.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

/**
 * @author: Fierce
 * @Date: 2021/2/6 21:57
 */
@Service
public class UserServiceImpl extends BaseService<User> implements UserService {

    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    UserMapper userMapper;

    @Override
    public User findByUsername(String username) {
        Example example = new Example(User.class);
        example.createCriteria().andEqualTo("username", username);
        return userMapper.selectByExample(example).get(0);
    }

    @Override
    public boolean check(String currentPassword, String password) {

        return bCryptPasswordEncoder.matches(currentPassword,password);
    }


}
